package _interview75;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 435. 无重叠区间
 */
public class No435 {
    public int eraseOverlapIntervals(int[][] intervals) {
        Arrays.sort(intervals, Comparator.comparingInt(o -> o[1]));
        int ans = 0;
        int end = Integer.MIN_VALUE;
        for (int[] interval : intervals) {
            if (interval[1] >= end) {
                ans++;
                end = interval[2];
            }
        }
        return intervals.length - ans;
    }
}
